import time
import hmac
import hashlib
import base64

# Constant variables and Methods for MTurk API
ACCESS_KEY='AKIAIWRSYEUADSMOX4RQ'
SECRET_KEY='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'
SERVICE_NAME='AWSMechanicalTurkRequester'
SERVICE_VERSION = '2008-02-14'
#service_url=http://mechanicalturk.sandbox.amazonaws.com/?Service=AWSMechanicalTurkRequester
SERVICE_URL='http://mechanicalturk.sandbox.amazonaws.com/?'


def generate_timestamp(gmtime):
    return time.strftime("%Y-%m-%dT%H:%M:%SZ", gmtime)

def generate_signature(service, operation, timestamp, secret_access_key):
    my_sha_hmac = hmac.new(secret_access_key, service + operation + timestamp, hashlib.sha1)
    my_b64_hmac_digest = base64.encodestring(my_sha_hmac.digest()).strip()
    return my_b64_hmac_digest
